package com.hlhj.carview.aty

import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import com.hlhj.carview.BaseAty
import com.hlhj.carview.Iview.MyAdvView
import com.hlhj.carview.R
import com.hlhj.carview.adapter.MyAdvAdp
import com.hlhj.carview.bean.AdvListBean
import com.hlhj.carview.presenter.MyAdvPresenter
import kotlinx.android.synthetic.main.aty_myadv.*
import kotlinx.android.synthetic.main.lo_pubhead.*

/**
 * Created by Never Fear   on 2018\12\24 0024.
Never More....
 */
class MyAdvAty :BaseAty<MyAdvView,MyAdvPresenter>(), MyAdvView {
    private var adp:MyAdvAdp?=null
    private val datas=ArrayList<AdvListBean.InfoBean.DataBean>()
    private var page=1


    override fun setAdvList(advListBean: AdvListBean) {
        if (page==1){
            datas.clear()
        }
        datas.addAll(advListBean.info.data)
        adp?.notifyDataSetChanged()
    }

    override fun initView() {
        tvTittle.text="我的广告"
        adp= MyAdvAdp(datas)
        listView.adapter=adp
        listView.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)


    }

    override fun logicStart() {
        presenter?.getAdv(page.toString(),this)
    }

    override fun setListener() {
        btData.setOnClickListener {
            val intent = Intent(this, ProfitAty::class.java)
            startActivity(intent)
        }
        adp?.setOnItemClickListener { adapter, view, position ->
            val intent = Intent(this, AdvDetailAty::class.java)
            intent.putExtra("id",datas[position].advertising_id)
            intent.putExtra("name",datas[position].advertising_name)
            startActivity(intent)
        }
    }

    override fun bindView(): MyAdvView {
        return this
    }

    override fun createPresenter(): MyAdvPresenter {
        return MyAdvPresenter()
    }

    override fun getContentID(): Int {
        return R.layout.aty_myadv
    }
}